import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import 'package:simple/pub/ScreenAdapter.dart';

class Utils {
  int optInt(int val) {
    if (val > 0) return val;
    return 0;
  }

  static String optString(String val, String defaultVal) {
    if (null != val && val != "") return val;
    return defaultVal;
  }

  static showLoginDialog(BuildContext context) {
    showDialog(
        context: context,
        builder: (BuildContext context) {
          return CupertinoAlertDialog(
            content: ListBody(
              children: [
                Text('请重新登录'),
              ],
            ),
            actions: [
              CupertinoDialogAction(
                child: Text('取消',
                    style: TextStyle(
                        fontSize: ScreenAdapter.size(28),
                        color: Color(0xFF333333))),
                onPressed: () {
                  Navigator.of(context).pop();
                },
              ),
              CupertinoDialogAction(
                child: Text('确定',
                    style: TextStyle(
                        fontSize: ScreenAdapter.size(28),
                        color: Color(0xFFC40D3C))),
                onPressed: () {
                  Navigator.of(context).pop();
                  Navigator.pushNamed(context, '/account/login');
                },
              ),
            ],
          );
        });
  }
}
